<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="12">

          <a-col :md="4" :sm="8">
            <a-form-item label="车牌号">
              <a-input placeholder="请输入车牌号"
                       v-model="queryParam.vehicleNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="车场编号">
              <a-input placeholder="请输入车场编号"
                       v-model="queryParam.parkCode"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="4" :sm="8">
              <a-form-item label="交易日期">
                <a-input placeholder="请输入交易日期" v-model="queryParam.tdate"></a-input>
              </a-form-item>
            </a-col>

          </template>

          <a-col :md="2" :sm="4">
            <a-form-item>
              <a-date-picker placeholder="开始日期" @change="onChangeStartTime"/>
            </a-form-item>
          </a-col>
          <a-col :md="2" :sm="4">
            <a-form-item>
              <a-date-picker placeholder="结束日期" @change="onChangeEndTime"/>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <div class="table-operator">

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"

        @change="handleTableChange">

        <span slot="action" slot-scope="text, records">
          <a @click="handleEdit(records)">详情</a>
        </span>


      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <b2cOrderqrySearchV1Log-modal ref="modalForm" @ok="modalFormOk"></b2cOrderqrySearchV1Log-modal>
  </a-card>
</template>

<script>
import B2cOrderqrySearchV1LogModal from './modules/B2cOrderqrySearchV1LogModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {deleteAction, getAction, downFile} from '@/api/manage'
import {filterObj} from '@/utils/util';

export default {
  name: "B2cOrderqrySearchV1LogList",
  mixins: [JeecgListMixin],
  components: {
    B2cOrderqrySearchV1LogModal
  },
  data() {
    return {
      description: 'B2C支付订单结果管理管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
           width: 100,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '停车场编号',
           width: 130,
          align: "center",
          dataIndex: 'parkCode'
        },
        {
          title: '停车场名称',
          // width: 130,
          align: "center",
          dataIndex: 'parkName'
        },
        {
          title: '交易日期',
          // width: 130,
          align: "center",
          dataIndex: 'tdate'
        },
        {
          title: '车牌号',
          // width: 130,
          align: "center",
          dataIndex: 'vehicleNum'
        },
        {
          title: '返回码',
          // width: 130,
          align: "center",
          dataIndex: 'returnCode'
        },
        {
          title: '返回码说明',
          // width: 130,
          align: "center",
          dataIndex: 'returnMsg'
        },
        {
          title: 'O2O交易方式',
          // width: 130,
          align: "center",
          dataIndex: 'o2oPaymode',
          customRender:function(t,r,index){
            switch (t)
            {
              case '0': t='其他'
                break
              case '1':t='e生活扫描商户二维码'
                break
              case '2':t='e生活扫描订单二维码'
                break
              case '3':t='工银e生活买单'
                break
              case '4':t='融e联扫描商户二维码'
                break
              case '5':t='融e联扫描订单二维码'
                break
              case '6':t='pos扫码付款'
                break
              case '7':t='商户之家扫码付款'
                break
              case '8':t='团购'
                break
              case '9':t='融e行主扫商户二维码'
                break
              case '10':t='融e行主扫订单二维码'
                break
              case '11':t='融e行pos扫码付款'
                break
              case '12':t='融e行商户之家扫码付款'
                break
              case '13':t='微信扫商户二维码'
                break
              case '14':t='微信扫订单二维码'
                break
              case '15':t='POS/MIS 扫描微信二维码'
                break
              case '16':t='商户之家扫描微信二维码'
                break
              case '17':t='银联商户扫描付款'
                break
              case '18':t='银联商户扫码付款（融e行）'
                break
              case '19':t='P OS扫码付款（e生活）'
                break
              case '20':t='商户之家扫码付款（e生活）'
                break
              case '21':t='银联商户扫码付款（e生活）'
                break
              case '22':t='支付宝扫描商户二维码'
                break
              case '23':t='支付宝扫描订单二维码'
                break
              case '24':t='POS/MIS扫描支付宝二维码'
                break
              case '25':t='商户之家扫描支付宝二维码'
                break
              case '26':t='POS扫银联二维码'
                break
              case '27':t='商户之家扫银联二维码'
                break
              case '28':t='融e行扫描境外商户二维码'
                break
              case '29':t='线上聚合支付（微信）'
                break
              case '30':t='线上聚合支付（支付宝）'
                break
              case '31':t='银联渠道扫描商户二维码'
                break
              case '32':t='银联渠道扫描订单二维码'
                break
              case '33':t='融e行扫银联二维码'
                break
              case '34':t='融e联扫银联二维码'
                break
              case '35':t='e生活扫银联二维码'
                break
            }
            return t
          }

        },
        {
          title: '调用接口名称',
          // width: 130,
          align: "center",
          dataIndex: 'consumerId'
        },
        {
          title: '订单号（工行）',
          // width: 130,
          align: "center",
          dataIndex: 'orderNo'
        },
        {
          title: '创建时间',
          // width: 130,
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          // width: 130,
          align: "center",
          scopedSlots: {customRender: 'action'},
        }
      ],
      url: {
        list: "/b2cpaymentpay/b2cOrderqrySearchV1Log/list",
        delete: "/b2cpaymentpay/b2cOrderqrySearchV1Log/delete",
        deleteBatch: "/b2cpaymentpay/b2cOrderqrySearchV1Log/deleteBatch",
        exportXlsUrl: "b2cpaymentpay/b2cOrderqrySearchV1Log/exportXls",
        importExcelUrl: "b2cpaymentpay/b2cOrderqrySearchV1Log/importExcel",
      },
      queryParam: {
        "opTime_begin": "",
        "opTime_end": "",
      },
      isorter: {
        column: 'createTime',
        order: 'desc',
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  created() {

    this.keyupEnter()
  },
  methods: {
    handleEdit: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "详情";
      this.$refs.modalForm.disableSubmit = false;
    },

    handleExportXls(fileName) {

      let startTime = this.queryParam.opTime_begin;
      let endTime = this.queryParam.opTime_end;
      let opDesc = this.queryParam.opDesc;
      let dayTime = startTime;
      if (startTime == "") {
        this.$message.error("请选择导出开始日期");
        return
      }
      if (endTime == "") {
        this.$message.error("请选择导出结束日期");
        return
      }
      if (startTime != "" && endTime != "") {
        if (startTime != endTime) {
          this.$message.error("仅支持1天数据导出,请选择导出日期");
          return
        }
      }

      if (startTime == "" && endTime != "") {
        this.$message.error("请选择开始时间");
        return
      }

      if (startTime != "" && endTime == "") {
        this.$message.error("请选择结束时间");
        return
      }


      this.queryParam.dayTime = dayTime;
      fileName = dayTime + fileName;
      let param = {...this.queryParam};
      if (this.queryParam.opTime_begin != "" && this.queryParam.opTime_end != "") {
        param.opTime_begin = this.queryParam.opTime_begin + " 00:00:00";
        param.opTime_end = this.queryParam.opTime_end + " 23:59:59";
      }

      downFile(this.url.exportXlsUrl, param).then((data) => {
        if (!data) {
          this.$message.warning("文件下载失败")
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data]), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data]))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link); //下载完成移除元素
          window.URL.revokeObjectURL(url); //释放掉blob对象
        }
      })
    },


    onChangeStartTime(date, dateString) {
      this.queryParam.opTime_begin = dateString;
    },

    onChangeEndTime(date, dateString) {
      this.queryParam.opTime_end = dateString;
    },


    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      
      var params = this.getQueryParams();//查询条件
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.handleB2cOrderqrySearchV1LogDataSource();
          this.ipagination.total = res.result.total;
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    },
    handleB2cOrderqrySearchV1LogDataSource() {

      for (let item of this.dataSource) {

        item.secorderFlag = item.secorderFlag === "0" ? "否" : "是";

        item.orderStatus = item.orderStatus === "0" ? "不按订单状态查询" : "查询状态为成功的订单";
        item.orderidType = item.orderStatus === "0" ? "外部商户自定义订单号" : "行内订单号";
        if (item.returnCode === "0") {
          item.returnCode = "交易成功";
        } else if (item.returnCode > Number("0")) {
          item.returnCode = "业务报错";
        } else {
          item.returnCode = "系统报错";
        }

        item.rjswitch = item.rjswitch === "0" ? "否" : "是";

        if (item.depFlag === "0") {
          item.depFlag = "未分期，全额付款";
        } else if (item.depFlag === "1") {
          item.depFlag = "商户分期";
        } else if (item.depFlag === "2") {
          item.depFlag = "客户分期";
        } else {
          item.depFlag = "贷记卡逸贷分期";
        }

        item.depfeepf = item.depfeepf === "1" ? "首次支付" : "分期支付";



        item.pointFlag = item.pointFlag === "0" ? "否" : "是";
        item.dzqFlag = item.dzqFlag === "0" ? "否" : "是";
        item.tgflag = item.tgflag === "0" ? "否" : "是";


      }

    },


    searchQuery() {
      let startTime = this.queryParam.opTime_begin;
      let endTime = this.queryParam.opTime_end;

      if (startTime != "" && endTime != "") {
        if (startTime > endTime) {
          this.$message.error("开始时间不能大于结束时间");
          return
        }
      }

      if (startTime == "" && endTime != "") {
        this.$message.error("请选择开始时间");
        return
      }

      if (startTime != "" && endTime == "") {
        this.$message.error("请选择结束时间");
        return
      }

      this.loadData(1);
    },

    getQueryParams() {

      
      var param = Object.assign({}, this.isorter, this.queryParam);
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      if (this.queryParam.opTime_begin != "" && this.queryParam.opTime_end != "") {
        param.startTime = this.queryParam.opTime_begin + " 00:00:00";
        param.endTime = this.queryParam.opTime_end + " 23:59:59";
      }

      // delete param.createTimeRange; // 时间参数不传递后台
      return filterObj(param);
    },
    batchDel: function () {

      if (!this.url.deleteBatch) {
        this.$message.error("请设置url.deleteBatch属性!")
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
        return;
      } else {
        var ids = "";
        for (var a = 0; a < this.selectionRows.length; a++) {
          ids += this.selectionRows[a].invateuserdetailId + ",";
        }
        var that = this;
        this.$confirm({
          title: "确认删除",
          content: "是否删除选中数据?",
          onOk: function () {
            deleteAction(that.url.deleteBatch, {ids: ids}).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.message);
              }
            });
          }
        });
      }
    },
    handleDelete: function (invateuserdetailId) {
      if (!this.url.delete) {
        this.$message.error("请设置url.delete属性!")
        return
      }
      var that = this;
      deleteAction(that.url.delete, {invateuserdetailId: invateuserdetailId}).then((res) => {
        if (res.success) {
          that.$message.success(res.message);
          that.loadData();
        } else {
          that.$message.warning(res.message);
        }
      });
    },


    keyupEnter() {
      document.onkeydown = e => {
        let body = document.getElementsByTagName('body')[0]
        if (e.keyCode === 13) {
          this.loadData(1);
        }
      }
    },

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
